﻿using System.Web.Mvc;
using Common.Objects.Enums;
using Common.Resources;

namespace Common.Objects.Column
{
    public class ImageLinkColumn : BaseColumn
    {
        public string ActionUrl { get; set; }

        public string Value { get; set; }

        public string ImageSrc { get; set; }

        public ImageLinkColumn(string url, string value, string imageSrc)
        {
            ActionUrl = url;
            Value = value;
            ImageSrc = imageSrc;
        }

        public override string Render()
        {
            TagBuilder linkTag = new TagBuilder("a");
            linkTag.Attributes.Add("href", ActionUrl);
            TagBuilder img = new TagBuilder("img");
            img.Attributes.Add("src", ImageSrc);
            img.Attributes.Add("title", Value);
            linkTag.InnerHtml += img.ToString(TagRenderMode.Normal);
            if (ColumnType == ColumnType.ImageLink)
            {
                return string.Format(HtmlResources.SelectColumnTemplate, linkTag.ToString(TagRenderMode.Normal));
            }

            return linkTag.ToString(TagRenderMode.Normal);
        }
    }
}